package com.wey;


import lombok.Data;

public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    private Boolean success;

    public R() {
    }

    public R(T data) {
        this.data = data;
    }

    public R(Integer code, String msg, Boolean success) {
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public R(Integer code, String msg, T data, Boolean success) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.success = success;
    }

    public static <T> R<T> success() {
        return success("操作成功");
    }

    public static <T> R<T> success(String msg) {
        return new R(200, msg, null, true);
    }

    public static <T> R<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> R<T> error(Integer code, String msg) {
        return new R<>(code, msg, null, false);
    }

    public static <T> R<T> error() {
        return error("操作失败");
    }

    public static <T> R<T> data(T data) {

        return data(data, "操作成功");
    }

    public static <T> R<T> data(T data, String msg) {

        return new R<>(200, msg, data, true);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean isSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
